June 8,2020

Introduction

DATE:June 8,2020

We are going to reate a web page presentation using R Markdown that features a plot created with Plotly. We will host our webpage on either GitHub Pages. Our webpage will contain the date that we created the document, and a plot created with Plotly.

Note : We will use the diamond dataset for this task

Lets move on….

Loading Plotly Package And Diamond Dataset

If you haven’t install the plotly package install it by using the command install.packages("plotly").

# loading the plotly package
library(plotly) 

# loading the diamond dataset and assign it to variable data
data <- diamonds[sample(nrow(diamonds), 2500), 
                 c("carat", "price", "clarity", "depth")]

Examine the Diamond Dataset

# checking the dimensions of the dataset
dim(data) 
[1] 2500    4
# checking the variable names in the dataset
names(data)
[1] "carat"   "price"   "clarity" "depth"  

Examine the Diamond Dataset

# examine the descriptive statistics 
summary(data) 
     carat            price            clarity        depth      
 Min.   :0.2300   Min.   :  326.0   SI1    :604   Min.   :55.80  
 1st Qu.:0.3975   1st Qu.:  944.8   VS2    :545   1st Qu.:61.10  
 Median :0.7000   Median : 2341.0   SI2    :425   Median :61.90  
 Mean   :0.7900   Mean   : 3842.8   VS1    :369   Mean   :61.79  
 3rd Qu.:1.0400   3rd Qu.: 5128.0   VVS2   :247   3rd Qu.:62.60  
 Max.   :5.0100   Max.   :18781.0   VVS1   :189   Max.   :70.80  
                                    (Other):121                  

Creating 2D and 3D Scatter Plots

# 2D plot
plot2D <- plot_ly(data, x = ~carat, y = ~price, color = ~carat,
        size = ~carat, text = ~paste("Clarity: ", clarity))

# 3D plot
plot3D <- plot_ly(data, x = ~carat, y = ~price, z = ~depth,
        color = ~carat, size = ~carat, 
        text = ~paste("Clarity: ", clarity)) 

2D Plot

# calling the 2D plot
plot2D

3D Plot

# calling the 3D plot
plot3D

THANK YOU!